﻿package de.gameduell.net.src.communication {
	import de.gameduell.framework.application.protocol.Protocol;
	import de.gameduell.framework.application.protocol.SingleplayerProtocol;
	import de.gameduell.framework.debug.Debug;
	import de.gameduell.net.src.communication.ICommunication;
	import de.gameduell.net.src.message.IMessage;
	import de.gameduell.net.src.protocol.IProtocol;	

	public class Standalone extends BaseCommunication implements ICommunication {
	
		public function Standalone(){
			super("Standalone");
		}
		
		public function connect():void {
			dispatchEvent(new CommunicationEvent(CommunicationEvent.CONNECTED));
		}
		
		public function send(requestType:String, parameters:Array):IMessage {
			switch(requestType){
				case Protocol.LOADED:
					dispatchEvent(new ServerMessageEvent(Protocol.LOADED,[]));
					break;
				case Protocol.ABORT:
					dispatchEvent(new ServerMessageEvent(SingleplayerProtocol.LEAVE,[]));
					break;
				case SingleplayerProtocol.END:
					dispatchEvent(new ServerMessageEvent(SingleplayerProtocol.LEAVE,[]));
					break;
			}
			var message:IMessage = protocol.createMessage(requestType, parameters, messageQueue.nextMessageId);
			return message;
		}
		
		public function fakeServerMessage(messageType:String,messageBody:Array):void{
			Debug.trace("Standalone::fakeServerMessage " + messageType, Debug.CONNECTION);
			var message:IMessage = protocol.createMessage(messageType, messageBody, messageQueue.nextMessageId);	
			dispatchEvent(new ServerMessageEvent(message.requestType, message.parameters));
		}

		public function sync():void {
		}
		
		public function terminate():void {
		}
		
		public function get debugModeEnabled():Boolean {
			return true;
		}
	}
}